﻿package UIComponents
{
	import Classes.GameUtils.GU_Color;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：May 10, 2012 11:23:25 AM 
	 */ 
	public class SevenDaysRewardUI extends Sprite
	{
		private var closeBtn:DisplayObject;
		public function SevenDaysRewardUI()
		{
			init();
		}
		
		private function init():void
		{
			closeBtn=this.getChildByName("closeBtn");
			this.closeBtn.addEventListener(MouseEvent.CLICK,onClick);
		}
		
		private function onClick(e:MouseEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.CLOSE,true));
		}
		
		
		private function getDisplayByIndex(index:int):DisplayObjectContainer
		{
			if(index<0 || index>7)throw new Error("索引出错");
			return (this.getChildByName("d"+(index+1))) as DisplayObjectContainer;
		} 
		
		public function setRewardData(arr:Array,isLq:Boolean):void
		{
			for(var i:int=0;i<7;i++)
			{
				var dc:DisplayObjectContainer=this.getDisplayByIndex(i);
				var obj:Object=arr[i]
				if(null==obj)
				{
					dc.visible=false;
				}else{
					var tmpArr:Array=obj.items as Array;
					for(var j:int=0;j<tmpArr.length;j++)
					{
						var endObj:Object=tmpArr[j]
						var displayObj:DisplayObject=endObj.icon;
						displayObj.width=35;
						displayObj.height=35;
						(dc.getChildByName("icon"+j) as IconContainer).addPic(displayObj,displayObj["displayViewIconName"]);
						((dc.getChildByName("itemNum"+j) as DisplayObjectContainer).getChildByName("txt_num") as TextField).text=String(endObj.itemNum);
						((dc.getChildByName("itemNum"+j) as DisplayObjectContainer).getChildByName("txt_num") as TextField).mouseEnabled=false;
					}
					//设置颜色状态  1表示 领取 2表示 不可领 3表示 已过期 4表示 已领取
					var s:int=obj.statue;
					var dayDis:DisplayObject=dc.getChildByName("dayicon");
					var bg:DisplayObject=dc.getChildByName("bg");
					if(s==1 && !isLq)
					{
						//设置其亮度
						dayDis.filters=null;
						bg.filters=[GU_Color.instance.changeLD(5),GU_Color.instance.changeBHD(20),GU_Color.instance.changeDBD(40),GU_Color.instance.changeSX(0)];
						
					}else{
						//设置其亮度为非色
						dayDis.filters=GU_Color.getSmallDarker();
						bg.filters=null;
					}
//					trace("ssss="+s);
					switch(s)
					{
						
						case 1:
							dc.getChildByName("lqBtn").visible=true;
							dc.getChildByName("bklqBtn").visible=false;
							dc.getChildByName("gqBtn").visible=false;
							dc.getChildByName("ylqBtn").visible=false;
							if(isLq)
							{
								dc.getChildByName("lqBtn").visible=false;
								dc.getChildByName("ylqBtn").visible=true;
							}
							break;
						case 2:
							dc.getChildByName("lqBtn").visible=false;
							dc.getChildByName("bklqBtn").visible=true;
							dc.getChildByName("gqBtn").visible=false;
							dc.getChildByName("ylqBtn").visible=false;
							break;
						case 3:
							dc.getChildByName("lqBtn").visible=false;
							dc.getChildByName("bklqBtn").visible=false;
							dc.getChildByName("gqBtn").visible=true;
							dc.getChildByName("ylqBtn").visible=false;
							break;
						case 4:
							dc.getChildByName("lqBtn").visible=false;
							dc.getChildByName("bklqBtn").visible=false;
							dc.getChildByName("gqBtn").visible=false;
							dc.getChildByName("ylqBtn").visible=true;
//							trace(" ylqBtn= "+dc.getChildByName("ylqBtn").visible +" bklqBtn= "+dc.getChildByName("bklqBtn").visible)
							break;
					}
				}
				
				dc.getChildByName("lqBtn").addEventListener(MouseEvent.CLICK,clickFun);
			}
		}
		
		private function clickFun(e:MouseEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.CUSTOMCALLBACK,true));
		}
		
	}
}
